package com.wyl.libbase.base

import androidx.databinding.ObservableBoolean
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.google.gson.JsonSyntaxException
import com.lzg.extend.onFailed
import com.lzy.okgo.exception.HttpException
import com.lzy.okgo.exception.StorageException
import io.reactivex.disposables.CompositeDisposable
import org.json.JSONException
import java.net.ConnectException
import java.net.SocketTimeoutException
import java.net.UnknownHostException

open class BaseViewModel : ViewModel() {
    protected val disposables by lazy { CompositeDisposable() }

    /**
     * 正在请求数据加载中...
     */
//    val loading: ObservableBoolean = ObservableBoolean(true)
    val loading: MutableLiveData<Boolean> by lazy { MutableLiveData<Boolean>() }
    val error: MutableLiveData<String> by lazy { MutableLiveData<String>() }
    val success: MutableLiveData<String> by lazy { MutableLiveData<String>() }
    val toast: MutableLiveData<String> by lazy { MutableLiveData<String>() }

    override fun onCleared() {
        disposables.clear()


    }

    protected fun onError(exception: Throwable) {
        error.value = onFailed(exception)
    }


}